package main

import (
	"fmt"
	"time"
)

/**
2.8  类型别名
1. 非本地类型不能定义方法
2. 类型别名用=，编译后实际别名不存在。类型定义，是完全不同的类型，且不能用之前的方法
 */
type newInt int
type IntAlias =int//带=的才是别名，编译后实际不存在IntAlias这个类型

type myTime time.Duration

type youTime =time.Duration
const (
	Nanosecond  myTime = 1
	Microsecond          = 1000 * Nanosecond
	Millisecond          = 1000 * Microsecond
	Second               = 1000 * Millisecond
	Minute               = 60 * Second
	Hour                 = 60 * Minute
)

func main()  {


	var a newInt
	var b IntAlias

	fmt.Printf("a type is %T\n",a)//a type is main.newInt
	fmt.Printf("b type is %T\n",b)//	b type is int
	var my myTime
	my.Canset("hee")
	my.MyHours()

	var you youTime

	you.String()
	you.Hours()



}

//cant define new methods on non-local type time duration,如果上面的type 把=去掉就行
func (m myTime) Canset(a string){
	fmt.Println(a)
}
func (d myTime) MyHours() float64 {
	hour := d / Hour
	nsec := d % Hour
	return float64(hour) + float64(nsec)/(60*60*1e9)
}
